package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RewardsPunishment;
import com.ruoyi.system.service.IRewardsPunishmentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖惩管理Controller
 * 
 * @author ruoyi
 * @date 2023-04-11
 */
@Controller
@RequestMapping("/system/punishment")
public class RewardsPunishmentController extends BaseController
{
    private String prefix = "system/punishment";

    @Autowired
    private IRewardsPunishmentService rewardsPunishmentService;

    @RequiresPermissions("system:punishment:view")
    @GetMapping()
    public String punishment()
    {
        return prefix + "/punishment";
    }

    /**
     * 查询奖惩管理列表
     */
    @RequiresPermissions("system:punishment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RewardsPunishment rewardsPunishment)
    {
        startPage();
        List<RewardsPunishment> list = rewardsPunishmentService.selectRewardsPunishmentList(rewardsPunishment);
        return getDataTable(list);
    }

    /**
     * 导出奖惩管理列表
     */
    @RequiresPermissions("system:punishment:export")
    @Log(title = "奖惩管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RewardsPunishment rewardsPunishment)
    {
        List<RewardsPunishment> list = rewardsPunishmentService.selectRewardsPunishmentList(rewardsPunishment);
        ExcelUtil<RewardsPunishment> util = new ExcelUtil<RewardsPunishment>(RewardsPunishment.class);
        return util.exportExcel(list, "奖惩管理数据");
    }

    /**
     * 新增奖惩管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存奖惩管理
     */
    @RequiresPermissions("system:punishment:add")
    @Log(title = "奖惩管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RewardsPunishment rewardsPunishment)
    {
        return toAjax(rewardsPunishmentService.insertRewardsPunishment(rewardsPunishment));
    }

    /**
     * 修改奖惩管理
     */
    @RequiresPermissions("system:punishment:edit")
    @GetMapping("/edit/{rpId}")
    public String edit(@PathVariable("rpId") Long rpId, ModelMap mmap)
    {
        RewardsPunishment rewardsPunishment = rewardsPunishmentService.selectRewardsPunishmentByRpId(rpId);
        mmap.put("rewardsPunishment", rewardsPunishment);
        return prefix + "/edit";
    }

    /**
     * 修改保存奖惩管理
     */
    @RequiresPermissions("system:punishment:edit")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RewardsPunishment rewardsPunishment)
    {
        return toAjax(rewardsPunishmentService.updateRewardsPunishment(rewardsPunishment));
    }

    /**
     * 删除奖惩管理
     */
    @RequiresPermissions("system:punishment:remove")
    @Log(title = "奖惩管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rewardsPunishmentService.deleteRewardsPunishmentByRpIds(ids));
    }

//    /**
//     * 清除奖惩记录
//     */
//    @RequiresPermissions("system:punishment:clearrpinfo")
//    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
//    @PostMapping( "/clearrpinfo")
//    @ResponseBody
//    public AjaxResult clearrpinfo()
//    {
//        return toAjax(rewardsPunishmentService.clearRpInfo());
//    }

    /**
     * 记一次迟到
     */
    @RequiresPermissions("system:punishment:lateplus")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PostMapping( "/lateplus")
    @ResponseBody
    public AjaxResult lateplus(long employeeId)
    {
        return toAjax(rewardsPunishmentService.latePlus(employeeId));
    }

    /**
     * 记全勤
     */
    @RequiresPermissions("system:punishment:setattendance")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PostMapping( "/setattendance")
    @ResponseBody
    public AjaxResult setattendance(long employeeId)
    {
        return toAjax(rewardsPunishmentService.setAttendance(employeeId));
    }


    /**
     * 记所有人全勤
     */
    @RequiresPermissions("system:punishment:setattendanceall")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PostMapping( "/setattendanceall")
    @ResponseBody
    public AjaxResult setattendanceall()
    {
        return toAjax(rewardsPunishmentService.setAttendanceAll());
    }

    /**
     * 取消全勤
     */
    @RequiresPermissions("system:punishment:cancelattendance")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PostMapping( "/cancelattendance")
    @ResponseBody
    public AjaxResult cancelattendance(long employeeId)
    {
        return toAjax(rewardsPunishmentService.cancelAttendance(employeeId));
    }

}
